package servlet;

import dao.UserDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "PageCountServlet", value = "/PageCountServlet")
public class PageCountServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String id=request.getParameter("id");
        String res= (String) request.getSession().getAttribute("res");
        if(id.equals("pr")){
            //上一页

            if(res.equals("1")){//第一页则删除
                request.getSession().removeAttribute("res");
            }else{
                int st=Integer.parseInt(res)-1;
                String end=String.valueOf(st);
                request.getSession().setAttribute("res",end);

            }
            response.sendRedirect("manage.jsp");
        }
       else  if(id.equals("ne")){
            //下一页
            int a=new UserDao().getCount();
            a=a/8+1;
            int end = Integer.parseInt(res);
            if(end==a){
                //不需要操作
            }
            if(end<a){
                //不需要操作
                request.getSession().setAttribute("res",String.valueOf(end+1));
            }
            if(end>a){

            }

            response.sendRedirect("manage.jsp");
        }

        else{
            request.getSession().setAttribute("res",id);
            response.sendRedirect("manage.jsp");

        }
    }
}
